<template>
	<view class="content">
		<view class="search-box flexWrap">
			<input placeholder="请输入关键词" placeholder-class="placeholderClass" v-model="keywords"/>
			<image src="../../static/shop/search-icon.png" class="search-icon" @tap="getData()"></image>
		</view>
		<swiper class="banner-box"  :autoplay="true"  :interval="3000" :duration="1000">
			<swiper-item class="banner-item" v-for="(item, index) in bannerList" :key="index" @tap="previewImage(item.url_image,bannerList)">
				<view class="shop-img">
					<image :src="item.url_image" mode="aspectFill"></image>
				</view>
			</swiper-item>
		</swiper>
		<scroll-view scroll-x="true" style="margin-top: 48upx;">
			<view class="type-box flexWrap">
				<view class="type-item flexWarpCenterColumn"  v-for="(item,index) in categoryList" :key="index" @tap="goPage('/pages/shop/shopList?categoryId='+item.id)">
					<image class="type-icon" :src="item.image"></image>
					<text>{{item.name}}</text>
				</view>
			</view>
		</scroll-view>
		<view class="gn-box flexWrap">
			<view class="gn-item flexWrap" @tap="goPage('/pages/shop/shopOrderList')">
				<view class="flexWrapNo">
					<image class="gn-icon" src="../../static/shop/order-icon.png"></image>
					<text>订单</text>
				</view>
				<image src="/static/shop/more.png" class="more"></image>
			</view>
			<view class="gn-item flexWrap" @tap="goPage('/pages/shop/cart')">
				<view class="flexWrapNo">
					<image class="gn-icon" src="../../static/shop/cart-icon.png"></image>
					<text>购物车</text>
				</view>
				<image src="/static/shop/more.png" class="more"></image>
			</view>
		</view>
		<view class="shop-box">
			<view class="title-box flexWrap">
				<view><text class="big">推荐</text> 乒个乓好物</view>
				<!-- <view>更多<text class="icon-more"></text></view> -->
			</view>
			<view class="shop-cont flexWrap">
				<view class="shop-item" v-for="(item,index) in recommenProList" :key="index" @tap="goPage('/pages/shop/shopDetails?goodsId='+item.id)">
					<view class="shop-img">
						<image :src="item.image"></image>
					</view>
					<view class="shop-name">{{item.title}}</view>
					<view class="price-box">
						<text>¥{{item.price||'--'}}</text>
						<text class="old-price">原价¥{{item.marketprice||'--'}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bannerList:[],
				categoryList:[],
				recommenProList:[],
				keywords:""
			};
		},
		onLoad() {
			this.getData();
		},
		onShareAppMessage() {
			return {
				
			};
		},
		methods:{
			getData(){
				this.$request.post(this.$api.shopHome, {
					keywords:this.keywords
				}, {}).then(res => {
					if (res.code==1) {
						let {
							data = {}
						} = res;
						this.categoryList=data.categoryList
						this.bannerList=data.bannerList
						this.recommenProList=data.recommenProList
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		padding: 30upx;
	}
	.search-box{
		height: 80rpx;
		background: #1D1C5C;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		border: 2rpx solid #312F80;
		padding: 0 28upx;
		input{
			flex: 1;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #26BCFD;
		}
		.placeholderClass{
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #26BCFD;
		}
		.search-icon{
			width: 40upx;
			height: 40upx;
		}
	}
	.banner-box{
		height: 380upx;
		margin-top: 28upx;
		.banner-item{
			height: 380upx;
			border-radius:16upx;
			overflow: hidden;
			.shop-img{
				height: 100%;
			}
		}
	}
	.type-box{
		.type-item{
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			margin-right: 50upx;
			flex: none;
			.type-icon{
				border-radius: 10upx;
				overflow: hidden;
			}
			.type-icon{
				width: 96upx;
				height: 96upx;
				margin-bottom: 16upx;
			}
		}
	}
	.gn-box{
		margin-top: 20upx;
		.gn-item{
			width: 270rpx;
			height: 96rpx;
			background: #1D1C5C;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			padding: 0 28upx;
			font-size: 32upx;
			color: #82819B;
			.gn-icon{
				width: 80upx;
				height: 80upx;
			}
			.more{
				width: 40upx;
				height: 40upx;
			}
		}
	}
	.shop-box{
		margin-top: 48upx;
		.title-box{
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #47476C;
			.big{
				font-size: 32rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				margin-right: 12upx;
			}
			.icon-more{
				border-color: #47476C;
			}
		}
		.shop-cont{
			margin-top: 32upx;
			flex-wrap: wrap;
			.shop-item{
				margin-bottom: 40upx;
				width: 48%;
				.shop-img{
					width: 100%;
					height: 324rpx;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					overflow: hidden;
				}
				.shop-name{
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #82819B;
					margin-top: 24upx;
				}
				.price-box {
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					color: #26BCFD;
				
					.old-price {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #82819B;
						margin-left: 18upx;
						text-decoration: line-through;
					}
				}
			}
		}
	}
</style>
